﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HF.Sale;
using HF.Framework;
using HF.BusinessComm;

public partial class ProductEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            initData();
    }
    private void initData()
    {
        if (Request["Product_Code"] != null)
        {
            Product p = new Product();
            p.GetProductInfo(Request["Product_Code"].ToString());
            tbxProductCode.Text = p.Product_Code;
            tbxProductName.Text = p.Product_Caption;
            tbxProductType.Text = p.Product_Type;
            tbxProductUnit.Text = p.Product_Unit;
            tbxProductPrice.Text = p.Product_Price.ToString();
            tbxProductMemo.Text = p.Product_Memo;

        }
        else
        {
            tbxProductCode.Text = BusinessComm.GetDeciCode("PRODUCT",6);
 
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (Product.ProductExists(tbxProductCode.Text))
        {
            WorkDialog.ShowMessage(this,tbxProductCode.Text+"该编号的产品已存在,编号不能重复!!");
            return;
        }
        if (tbxProductCode.Text.Length <= 0)
        {
            WorkDialog.ShowMessage(this, "编号不能为空!!");
            return;
        }
        try
        {
            Product p = new Product();
            p.Product_Code = tbxProductCode.Text;
            p.Product_Caption = tbxProductName.Text;
            p.Product_Type = tbxProductType.Text;
            p.Product_Unit = tbxProductUnit.Text;
            p.Product_Price = Convert.ToDouble(tbxProductPrice.Text);
            p.Product_Memo = tbxProductMemo.Text;
            p.Insert();
            WorkDialog.ShowMessage(this, "增加成功!");
        }
        catch (Exception ex)
        {
            WorkDialog.ShowMessage(this,"增加错误:"+ex.Message.ToString());
        }
    }
    
    protected void btnModify_Click(object sender, EventArgs e)
    {
        if (tbxProductCode.Text.Length <= 0)
        {
            WorkDialog.ShowMessage(this, "编号不能为空!!");
            return;
        }
        try
        {
            Product p = new Product();
            p.Product_Code = tbxProductCode.Text;
            p.Product_Caption = tbxProductName.Text;
            p.Product_Type = tbxProductType.Text;
            p.Product_Unit = tbxProductUnit.Text;
            p.Product_Price = Convert.ToDouble(tbxProductPrice.Text);
            p.Product_Memo = tbxProductMemo.Text;
            p.Update();
            WorkDialog.ShowMessage(this, "修改成功!");
        }
        catch (Exception ex)
        {
            WorkDialog.ShowMessage(this, "修改错误:" + ex.Message.ToString());
        }
    }
}
